home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 888 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.1 KB

  1. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  2. Message-ID: <315A5C7A.6AF5@cs.tu-berlin.de>
  3. X-Original-Date: Thu, 28 Mar 1996 10:31:38 +0100
  4. Path: in2.uu.net!bounce-back
  5. Date: 28 Mar 96 09:38:43 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: "explicit" default constructor?
  9. Organization: Technical University of Berlin
  10. References: <31588662.F1@cs.tu-berlin.de> <4jbqog$78i@engnews1.Eng.Sun.COM>
  11. X-Mailer: Mozilla 2.0 (Win95; I)
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMVpebeEDnX0m9pzZAQEI0AF8C6YpDNsbyEL1eTmYXDWN6JvM0s9/AJgq
  14.     hsZVpdG8FnSlyG+FJkGTOKmrsHT/ZxWz
  15.     =R5Uq
  16.  
  17. Steve Clamage wrote:
  18.  
  19. > In article F1@cs.tu-berlin.de, Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  20. > writes:
  21. > > as I read the section [class.conv.ctor] of the DWP, I get the
  22. > > impression that the description of converting and non-converting
  23. > > constructors applies to all constructors, i.e. a constructor is either
  24. > > converting or non-converting. A non-converting constructor creates an
  25. > > object "only where a constructor call is  explicitly  indicated by the
  26. > > syntax". This has no implications on constructors with more than one
  27. > > parameter, but what about the default constructor? Should a default
  28. > > constructor call be really indicated by the syntax and if so, how is it
  29. > > to be done? What if the default constructor is declared "explicit"?
  30. >
  31. > A converting constructor is one which can be called with a single parameter.
  32. > The default constructor isn't a converting constructor except in the
  33. > case of a constructor with all parameters having default values.
  34. > If a constructor has no parameters, declaring it "explicit" has no effect,
  35. > since it can never be invoked for a conversion.
  36.  
  37. Exactly this is my question. Does this section deal only with constructors 
  38. with one parameter ( i.e. those that could be converting )? I read it this 
  39. way: if a constructor is not a converting constructor, i.e. it either doesn't 
  40. have exactly one parameter or is declared explicit, it is a non-converting 
  41. constructor and a call should be explicitly indicated by the syntax. In this 
  42. case the default constructor is non-converting.
  43.  
  44. > If a constructor's parameters all have default values, it can be a
  45. > converting constructor, and declaring it "explicit" prevents it from
  46. > being invoked implicitly.
  47.  
  48. Yes, I've had this in mind, too. In the following case:
  49.  
  50. class A
  51. {
  52.  explicit A( int x=0 );
  53. };
  54.  
  55. how do you call the default constructor? Can it still be invoked implicitly 
  56. and what is the "explicit" syntax if not? IMO, something like
  57.  
  58. A a;
  59.  
  60. is not explicit ( maybe I'm wrong here and this does explicitly call the 
  61. default constructor explicitly - but where does the DWP define it? ). An 
  62. explicit call would rather be
  63.  
  64. A a();
  65.  
  66. but what is the point in using this syntax?
  67.  
  68. Bye
  69.  
  70. Roman
  71. ---
  72. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  73. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  74. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  75. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  76. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  77.